package com.yanqu.road.server.cmd.wineshop;

import com.yanqu.road.pb.wineshop.WineShopProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wineshop.WineShopModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.manger.ForbiddenMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @author ：zfr
 * @date ：2021/7/20 11:36
 */
@Cmd(code = GameProtocol.S_WINESHOP_CHANGE_NAME, desc = "酒肆改名")
public class WineShopChangeNickNameCmd extends AbstractCommand {
    private String nickName;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WineShopProto.WineShopChangeNameReqMsg msg = WineShopProto.WineShopChangeNameReqMsg.parseFrom(packet.getBytes());
        nickName = msg.getNickName();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        /**
         * 如果被禁用 则返回系统未开放
         */
        if (ForbiddenMgr.isForbiddenCmd(player.getUserId(), Protocol.S_WINESHOP_CHANGE_NAME)) {
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        ret = player.getModule(WineShopModule.class).changeNickName(nickName);
    }

    @Override
    public void sendData(GamePlayer player) {
        WineShopProto.WineShopChangeNameRespMsg.Builder respMsg = WineShopProto.WineShopChangeNameRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_WINESHOP_CHANGE_NAME, respMsg);
    }
}
